home *** CD-ROM | disk | FTP | other *** search
- /* #include files */
- #include "A4Stuff.h"
- #include "SetupA4.h"
- #include <StringCompare.h>
-
- /* #defines */
- #define kINITid 0
-
- #define SEGMENTED true /* define if we have a multiple segment INIT */
- #define kNumSegments 2 /* total number of segments, including INIT resource itself */
-
- #define kQuitDialogId -16552
- #define kFinderQuitAlertId 2210
- #define kFinderQuitAlertIdSecondary 2216
- #define kFinderCreator 'MACS'
-
- const Str63 kMyAppName = "\pQuitSomethingElse App";
-
- /* some globals local to this file */
- FSSpecPtr gLaunchFSSpec;
-
- /* Alert patch stuff */
- typedef pascal DialogItemIndex (*AlertProc)( SInt16 alertID, ModalFilterUPP modalFilter );
- AlertProc gOldAlertAddr;
- pascal DialogItemIndex AlertPatch( SInt16 alertID, ModalFilterUPP modalFilter );
-
- /* main */
- void main(void)
- {
- long oldA4;
- Handle h;
-
- /* set up our A4 context for _this file_ */
- oldA4 = SetCurrentA4();
- RememberA4();
-
- /* detach ourselves */
- h = Get1Resource('INIT', kINITid);
- if (h) DetachResource(h);
-
- /* now that we are sure that all segments have been loaded */
- /* (since we called at least one routine in each segment) */
- /* we can continue by detaching each one */
- #ifdef SEGMENTED
- {
- short i;
- for (i=kINITid+1;i<kNumSegments;++i) {
- h = Get1Resource('INIc', i); /* should NOT fail since each segment should already be loaded and locked */
- if (h) DetachResource(h);
- }
- }
- #endif
-
- /* patch Alert */
- gOldAlertAddr = (AlertProc)GetToolTrapAddress(_Alert);
- SetToolTrapAddress((UniversalProcPtr)AlertPatch, _Alert);
-
- cleanup:
- /* restore the a4 world */
- SetA4(oldA4);
- }
-
- /* AlertPatch */
- pascal DialogItemIndex AlertPatch( SInt16 alertID, ModalFilterUPP modalFilter )
- {
- long oldA4;
- DialogItemIndex itemHit = -1;
- ProcessSerialNumber thePSN;
- ProcessInfoRec info;
- OSErr theError;
- FSSpec processFSSpec, launchFSSpec;
- Boolean result = false;
- DialogItemIndex theDialogItemIndex = -1;
- LaunchParamBlockRec myLaunchParams;
- long foundDirID;
- short foundVRefNum;
- short j;
- AppParameters appToLaunch;
-
- /* use the global data in _this file_ */
- oldA4 = SetUpA4();
-
- // Look for the Finder.
- thePSN.lowLongOfPSN = kNoProcess;
- thePSN.highLongOfPSN = 0;
-
- info.processInfoLength = sizeof( FSSpec );
- info.processName = NULL;
- info.processAppSpec = &processFSSpec;
-
- theError = GetFrontProcess( &thePSN );
-
- if ( noErr == GetProcessInformation( &thePSN, &info ) ) {
- // DebugStr( "\pChecking front process." );
- if ( ( alertID == kFinderQuitAlertId || alertID == kFinderQuitAlertIdSecondary ) && info.processSignature == kFinderCreator ) {
- // DebugStr( "\pFound the Finder!" );
-
- theError = FindFolder( -1, kSystemFolderType, false, &foundVRefNum, &foundDirID );
- if ( theError == noErr ) {
- launchFSSpec.vRefNum = foundVRefNum;
- launchFSSpec.parID = foundDirID;
-
- for ( j = 0; j <= kMyAppName[ 0 ]; j++ )
- launchFSSpec.name[ j ] = kMyAppName[ j ];
-
- myLaunchParams.launchBlockID = extendedBlock;
- myLaunchParams.launchEPBLength = extendedBlockLen;
- myLaunchParams.launchFileFlags = 0;
- myLaunchParams.launchControlFlags = launchContinue + launchNoFileFlags;
- myLaunchParams.launchAppSpec = &launchFSSpec;
- myLaunchParams.launchAppParameters = &appToLaunch;
- appToLaunch.eventRefCon = ( unsigned long )&gLaunchFSSpec;
-
- theError = LaunchApplication( &myLaunchParams );
-
- if ( theError == noErr )
- result = true;
- }
- }
- }
-
- /* call through to the original Alert */
- if ( !result )
- theDialogItemIndex = gOldAlertAddr( alertID, modalFilter );
-
- /* restore the a4 world */
- RestoreA4(oldA4);
-
- return theDialogItemIndex;
- }
-
-